﻿Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' '''  AQUI VAN UNOS COMENTARIOS
        'Dim ctaBl As WSNegocios.CuentasBL = New WSNegocios.CuentasBL
        'Dim cta As WSEntidades.CatCuentasBE = New WSEntidades.CatCuentasBE
        'Dim respCod As Integer = 0
        'Dim respMsg As String = ""
        'cta.Rfc = "A&A010101AAA"
        'cta.Nombre = "TEST"
        'cta.Correo = "mquiahua21@gmail.com"
        'cta.Telefono = "NO IDENTIFICADO"
        'If (ctaBl.RegistrarCuenta(cta, respCod, respMsg)) Then
        '    MsgBox("cuenta registrada")
        'Else
        '    MsgBox("Cuenta no registrada" & vbCrLf & "Codigo: " & respCod & vbCrLf & "Mensaje: " & respMsg)
        'End If

        'Me.registraProducto()
        Me.actualizaProducto()
        'Dim ws As servCat.ServicioCatalogosClient = New servCat.ServicioCatalogosClient
        'Dim cert As WSEntidades.CertificadoBE = New WSEntidades.CertificadoBE()
        'Dim mnd As WSEntidades.MonedaBE = New WSEntidades.MonedaBE
        ''mnd.
        'Dim resp As WSEntidades.DetalleRespuesta = New WSEntidades.DetalleRespuesta
        'cert.CertificadoPublico = Convert.ToBase64String(Me.StreamFile("C:\Proyectos\Certificados\Prueba\CSDs\aad990814bp7_1210261233s.cer"))
        'cert.CertificadoPrivado = Convert.ToBase64String(Me.StreamFile("C:\Proyectos\Certificados\Prueba\CSDs\aad990814bp7_1210261233s.key"))
        'cert.ContraseñaPrivada = "12345678a"
        'cert.UsarEnCancelacion = False
        'Try
        '    If (ws.RegistrarCertificado("DlcdnvYNI9XFYS4qClPOqv2r4wVhC/yX6Y/x45+T/Vko1Jp7iMYY5rKbUE6lLBswq79zan8F299s38eQAs12Edbdm8Dkz7fNTBme3ToNYPyql/AzrecwcDdK7BlL4ZGZ",
        '                                        "aad990814bp7", cert, resp)) Then
        '        MsgBox("OK")
        '    Else
        '        MsgBox("ERROR")
        '    End If
        'Catch ex As Exception
        '    MsgBox(ex.Message & ex.StackTrace)
        'End Try



        'Dim empr As WSEntidades.empresaBE = New WSEntidades.empresaBE
        'Dim resp As WSEntidades.DetalleRespuesta = New WSEntidades.DetalleRespuesta
        'With empr
        '    .RFC = "quim7911253w3"
        '    .RazonSocial = "mqi2"
        '    .Correo = "a123@123.com"
        '    .DF_Calle = "12"
        '    .DF_Municipio = "orizaba"
        '    .DF_Estado = "Veracruz"
        '    .DF_Pais = "mexico"
        '    .DF_CP = "95123"
        '    .Telefono = "1234567890"
        '    .Logo = Me.StreamFile("C:\Users\Public\Pictures\2890122360_e3df2a6576.jpg")
        'End With
        'Try
        '    If (ws.ActualizaDatosFiscales("DlcdnvYNI9XFYS4qClPOqv2r4wVhC/yX6Y/x45+T/Vl8oEo1xMM8nOR7hBzUHf/TGXEt+kUcvYueT5ULNJ8d+i0mTPcomkgKi3ciP5gBOJLR55xsMBtAFxGxyBdMX65b", _
        '                                      empr, resp)) Then
        '        MsgBox("ok")
        '    Else
        '        MsgBox("err")
        '    End If
        'Catch ex As Exception
        '    MsgBox(ex.Message & ex.StackTrace)
        'End Try

    End Sub

    Private Function registraProducto()
        Dim ws As servCat.ServicioCatalogosClient = New servCat.ServicioCatalogosClient
        Dim prodBE As WSEntidades.ProductoBE = New WSEntidades.ProductoBE()
        'mnd.
        Dim resp As WSEntidades.DetalleRespuesta = New WSEntidades.DetalleRespuesta
        prodBE.Clave = "CLAVE"
        prodBE.Nombre = "NOMBRE"
        prodBE.UdeM = New WSEntidades.UdeMBE()
        prodBE.UdeM.IdUdeM = 1
        prodBE.DesglosaPrecio = False
        prodBE.PrecioUnitario = 105.2345
        prodBE.TipoBaseIVA = WSEntidades.Enumeraciones.tipoBaseParaIVA.Porcentaje
        prodBE.PorcentajeBaseIVA = 100
        prodBE.AplicaIEPS = False
        prodBE.AplicaISR = False
        prodBE.AplicaIVARET = False
        prodBE.Imagen = Me.StreamFile("C:\Users\Public\Pictures\Olympic-logo.png")
        Try
            If (ws.RegistrarProducto("DlcdnvYNI9XFYS4qClPOqv2r4wVhC/yX6Y/x45+T/Vko1Jp7iMYY5rKbUE6lLBswq79zan8F299s38eQAs12Edbdm8Dkz7fNTBme3ToNYPyql/AzrecwcDdK7BlL4ZGZ",
                                     prodBE, Nothing, resp)) Then
                MsgBox("OK")
            Else
                MsgBox("ERROR")
            End If
        Catch ex As Exception
            MsgBox(ex.Message & ex.StackTrace)
        End Try
    End Function

    Private Function actualizaProducto()
        Dim ws As servCat.ServicioCatalogosClient = New servCat.ServicioCatalogosClient
        Dim prodBE As WSEntidades.ProductoBE = New WSEntidades.ProductoBE()
        'mnd.
        Dim resp As WSEntidades.DetalleRespuesta = New WSEntidades.DetalleRespuesta
        prodBE.Clave = "CLAVE"
        prodBE.Nombre = "NOMBRE act3"
        prodBE.UdeM = New WSEntidades.UdeMBE()
        prodBE.UdeM.IdUdeM = 1
        prodBE.DesglosaPrecio = False
        prodBE.PrecioUnitario = 105.2345
        prodBE.TipoBaseIVA = WSEntidades.Enumeraciones.tipoBaseParaIVA.Porcentaje
        prodBE.PorcentajeBaseIVA = 100
        prodBE.AplicaIEPS = False
        prodBE.AplicaISR = False
        prodBE.AplicaIVARET = False
        'prodBE.Imagen = Me.StreamFile("C:\Users\Public\Pictures\serbia-150.jpg")
        prodBE.Imagen = Nothing
        Try
            If (ws.ActualizaProducto("DlcdnvYNI9XFYS4qClPOqv2r4wVhC/yX6Y/x45+T/Vko1Jp7iMYY5rKbUE6lLBswq79zan8F299s38eQAs12Edbdm8Dkz7fNTBme3ToNYPyql/AzrecwcDdK7BlL4ZGZ",
                                     prodBE, Nothing, resp)) Then
                MsgBox("OK")
            Else
                MsgBox("ERROR")
            End If
        Catch ex As Exception
            MsgBox(ex.Message & ex.StackTrace)
        End Try
    End Function

    Private Function StreamFile(ByVal filename As String) As Byte()
        Dim fs As New System.IO.FileStream(filename, IO.FileMode.Open, IO.FileAccess.Read)

        ' Create a byte array of file stream length
        Dim ImageData As Byte() = New Byte(fs.Length - 1) {}

        'Read block of bytes from stream into the byte array
        fs.Read(ImageData, 0, System.Convert.ToInt32(fs.Length))

        'Close the File Stream
        fs.Close()
        'return the byte data
        Return ImageData
    End Function
End Class
